Dynamic selection of data replacement protocol for multi-level cache

ABSTRACT

An improved technique for managing data replacement in a multi-level cache dynamically selects a data replacement protocol from among multiple candidates based on which data replacement protocol produces the greatest cache hit rate. The technique includes selecting one of multiple data replacement protocols using a random selection process that can be biased to favor the selection of certain protocols over others. Data are evicted from each level of the multi-level cache using the selected data replacement protocol, and the cache hit rate is monitored. The selected data replacement protocol is then rewarded in response to the detected cache hit rate. The selection process is repeated, and a newly selected data replacement protocol is put into use. Operation tends to converge on an optimal data replacement protocol that best suits the application and current operating environment of the multi-level cache.

BACKGROUND

Computerized systems commonly include caches to provide efficient access to stored data. With a typical cache, selected data stored on slower media with higher capacity are loaded onto faster media with lower capacity. For example, data stored on a disk may be pre-fetched and brought into a portion of memory (a cache), where the data may be accessed quickly and efficiently by running programs.

Caches are typically operated at or near their full data capacity. Once a cache becomes full, new data cannot be added to the cache, e.g., in response to a pre-fetch operation, until other data are removed. Various protocols for removing data from a cache, i.e., “data replacement protocols,” are known in the art, and include, for example, least recently used (LRU), first in first out (FIFO), random replacement, and relative distance to logical block address (LBA).

Because a cache stores much less data than the media it supports, access by running programs to desired data in the cache sometimes results in the desired data being found in the cache (a “cache hit”) but sometimes results in the desired data being absent from the cache (a “cache miss”).

Caches are sometimes constructed in multiple levels. For example, a first level of a cache may be very fast, a second level may be slower, and a third level may be slower still. Requests for data from the cache may first query the fastest level and may then query each slower level in turn, from faster to slower, until the requested data is found. Requests for data thus result in cache hits or misses for the multi-level cache as a whole. Such requests may also result in cache hits or misses for individual levels of the multi-level cache. The different levels of a multi-level cache are sometimes referred to in the art as “tiers.”

SUMMARY

Data replacement protocols of conventional caches are typically hard-coded into the cache designs. For example, some caches are configured always to use FIFO whereas others are configured always to use LRU. It has been recognized, however, that the “hit rate” of a cache, i.e., the ratio of cache hits to the sum of cache hits and cache misses, depends strongly on the data replacement protocol in use by the cache and that the optimal data replacement protocol may change over time. Thus, LRU may result in the highest cache hit rate in some circumstances, whereas random data replacement may work best in other circumstances. Yet conventional approaches to managing caches do not typically adapt their data replacement protocols as circumstances change. This drawback is detrimental to multi-level caches as well as to single-level caches.

In contrast with the conventional approach, an improved technique for managing data replacement in a multi-level cache dynamically selects a data replacement protocol from among multiple candidates based on which data replacement protocol produces the greatest cache hit rate. The technique includes selecting one of multiple data replacement protocols using a random selection process that can be biased to favor the selection of certain protocols over others. Data are evicted from each level of the multi-level cache using the selected data replacement protocol, and the cache hit rate is monitored. The selected data replacement protocol is then rewarded based on the detected cache hit rate, e.g., a biasing of the selection process is modified to change the likelihood that the selected data replacement protocol will again be selected in the future. The selection process is repeated, and a newly selected data replacement protocol is put into use. Each time a new selection is made, the cache hit rate is monitored and the selected protocol is rewarded in response to the cache hit rate. In this fashion, operation tends to converge on an optimal data replacement protocol that best suits the application and current operating environment of the cache.

Certain embodiments are directed to a method of managing data replacement in a multi-level cache. The method includes selecting, in accordance with a selection process, one of multiple data replacement protocols for evicting data from the multi-level cache. The selection process has a biasing that is adjustable to change the probability of selecting any of the data replacement protocols relative to the others. The method further includes evicting data from the cache using the selected data replacement protocol and detecting a hit rate of the cache after selecting the selected data replacement protocol. The method still further includes adjusting the biasing of the selection process, in response to detecting the hit rate of the cache after selecting the selected data replacement protocol, to vary the probability that the selected data replacement protocol will later be selected according to the selection process when subsequently selecting one of the data replacement protocols for evicting data from the cache.

In some examples, the hit rate of the multi-level cache is detected in response to individual read requests, such that a single cache hit for the multi-level cache is taken as a cache hit rate of 100% whereas a single cache miss is taken as a cache hit rate of 0%. In other examples, cache hits and misses are accumulated over a specified period of time or over a specified number of read requests and the hit rate of the multi-level cache is computed based on the accumulated results. In still other examples, each level of the multi-level cache is monitored for hit rate individually and the hit rates of the individual levels are combined to produce a hit rate for the multi-level cache as a whole. In some variants, the hit rate weights cache hits at faster levels of the multi-level cache more strongly than it weights cache hits at slower levels, such that higher aggregate hit rates are reported when the fastest levels of the cache perform better, even when the multi-level cache as a whole performs the same.

Other embodiments are directed to computerized apparatus and computer program products. Some embodiments involve activity that is performed at a single location, while other embodiments involve activity that is distributed over a computerized environment (e.g., over a network).

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

The foregoing and other features and advantages will be apparent from the following description of particular embodiments of the invention, as illustrated in the accompanying drawings, in which like reference characters refer to the same parts throughout the different views. In the accompanying drawings,

FIG. 1 is block diagram of example computing circuitry in which an improved technique for managing data replacement in a multi-level cache can be practiced;

FIG. 2 is a block diagram of the multi-level cache of FIG. 1;

FIG. 3 is a block diagram of the cache manager of FIG. 1; and

FIG. 4 is a flowchart showing an example process for managing data replacement in a multi-level cache, such as the one shown in FIG. 1.

DETAILED DESCRIPTION OF THE INVENTION

Embodiments of the invention will now be described. It is understood that such embodiments are provided by way of example to illustrate various features and principles of the invention, and that the invention hereof is broader than the specific example embodiments disclosed.

An improved technique for managing data replacement in a multi-level cache dynamically selects a data replacement protocol from among multiple candidates based on which data replacement protocol produces the greatest cache hit rate. Operation tends to converge on an optimal data replacement protocol that best suits the application and operating environment of the multi-level cache.

FIG. 1 shows example computing circuitry 100 in which improved techniques for managing data replacement in a cache can be conducted. The computing circuitry 100 includes a set of processors 110 (e.g., one or more processing chips and/or assemblies), memory 112, a user interface 160, and a network interface 170. The set of processors 110 executing instructions stored in the memory 112 forms a controller 114, which is constructed and arranged for performing various processes described herein. The memory 112 includes both volatile and non-volatile memory. The memory 112 stores instructions for realizing one or more applications 120 and a cache manager 130. The cache manager 130 includes a protocol selector 132. The memory 112 also includes a multi-level cache 140 and a disk 150. It is understood that the memory 112 may store a myriad of other constructs; however, these are omitted from FIG. 1 for the sake of simplicity. The protocol selector 132 is arranged to dynamically select data replacement protocols based on a detected hit rate of the multi-level cache 140. Data stored in the multi-level cache 140 can be identified as distinct “pages.” The act of reading data into the multi-level cache 140 is referred to as “Paging In,” whereas the act of evicting data from the cache 140 is referred to as “Paging Out.” The various elements of the computing circuitry 100 may be located at a single location or distributed across multiple locations, e.g., over a network.

In example operation, the multi-level cache 140 is configured as a read cache or as a read/write cache, i.e., one used for both read caching and write caching. Selected data are pre-fetched from the disk 150 and loaded into the cache 140. Data recently read from disk 150 are also typically stored in the cache 140, so that the data can be accessed again without undue delay. Once the cache 140 fills, it becomes necessary to evict some of the data stored in the cache 140 to make room for newly arriving data.

To evict data from the cache 140, the protocol selector 132 applies a random selection process to select one data replacement protocol from among multiple candidates. Although the selection process selects protocols randomly, the selection process can be biased such that certain protocols are more likely to be selected than others.

The cache manager 130 monitors the performance of the multi-level cache 140 operating with the selected data replacement protocol. If the hit rate of the cache 140 increases, the selected protocol is rewarded, such that the protocol selector 132 is more likely to select the selected protocol going forward. If the hit rate of the cache 140 decreases, the selected protocol may be “punished,” i.e., made less likely to be selected by the protocol selector 132 going forward.

The acts of selecting a data replacement protocol, monitoring the cache hit rate, and rewarding or punishing the selected data replacement protocol are repeated over and over again, e.g., in a loop. In some examples, these acts are repeated each time data are evicted from the cache 140 (i.e., on each Page Out), or after some number of Page Outs or after some period of time. Over the course of many iterations, a particular data replacement protocol tends to be rewarded more than the others. As the most rewarded data replacement protocol also tends to be the one that is selected most often, operation tends to converge on the best data replacement protocol for the circumstances.

FIG. 2 shows additional aspects of the improved technique. Here, the multi-level cache 140 is seen to include three cache levels, a level 1 cache 240, a level 2 cache 250, and a level 3 cache 260. In an example, the level 1 cache 240 includes fast memory and has relatively low capacity, the level 2 cache 250 includes slower memory and has greater capacity, and the level 3 cache 260 includes still slower memory with still greater capacity. Although three cache levels are shown, it is understood that the multi-level cache 140 can include any number of cache levels greater than one. The cache levels 240, 250, and 260 can be implemented with any suitable technology. In one example, the first cache level 240 is random access memory (RAM), the second cache level 250 is flash memory, and the third cache level 260 is a disk drive. In another example, the first cache level 240 is flash memory, the second cache level 250 is a Fibre Channel disk drive, and the third cache level 260 is a SATA disk drive. Many examples are contemplated.

The multi-level cache 140 receives Page In requests 210 and Page Out requests 214, e.g., from the cache manager 130. The Page In requests 210 specify data 212 to Page In, e.g., pages of data that have been pre-fetched from the disk 150, pages of data that have recently been read from the disk 150, and/or pages of data to be written to the disk 150, for example. The Page Out requests 214 specify pages of data 216 to be evicted from the cache 140 in accordance with a selected data replacement protocol. The multi-level cache 140 also receives read requests 218 for obtaining data from the cache 140. The read requests 218 generally originate from the applications 120 and are provided to the multi-level cache 140 via the cache manager 130. Each of the read requests 218 includes a request to obtain particular data from the cache 140 and results in either a cache hit or a cache miss. Generally, once the cache 140 is full, each Page In request 210 is accompanied by a corresponding Page Out request 214. However, read requests 218 do not typically correspond in time with Page In requests 210 or Page Out requests 214.

In operation, data 212 to Page In to the multi-level cache 140 are written to the level 1 cache 240 (i.e., to the fastest cache level). If the level 1 cache 240 is full, data 242 are evicted from the level 1 cache 240 to make room for the data 212, using the selected data replacement protocol. Such data 242 then become data to Page In to the level 2 cache 250. Similarly, if the level 2 cache is full, data 252 are evicted from the level 2 cache 250, using the selected data replacement protocol. Such data 252 then become the data to Page In to the level 3 cache 260. Likewise, if the level 3 cache 260 is full, data 216 are evicted from the level 3 cache 260, and thus from the multi-level cache 240 as a whole, using the selected data replacement protocol.

In an example, the cache manager 130 responds to read requests 218 by first checking the level 1 cache 240 to determine whether the level 1 cache 240 stores the requested data. If the requested data are present, the data are returned to the requestor. Otherwise, the cache manager 130 checks the level 2 cache 250. The requested data are returned to the requestor if found. Otherwise, the cache manager 130 checks the level 3 cache. In this fashion, faster cache levels are checked before slower cache levels to promote optimal performance.

It is understood that the multi-level cache 140 has a hit rate, based on the number of cache hits and cache misses to the cache 140 as a whole. Also, each of the cache levels 240, 250, and 260 has its own individual cache hit rate, based on the number of cache hits and cache misses at the respective cache level. It is understood that cache hits at higher levels of the multi-level cache 140 prevent lower levels from being checked, such that the hit rates of higher cache levels will be based on more data requests than the hit rates of lower levels.

As described, data 212 to Page In to the multi-level cache 140 travels in a single direction, from the level 1 cache 240 to the level 2 cache 250 and on to the level 3 cache 260. Data can be pushed down to a lower level cache, or can be pushed out of the cache 140 altogether. In some examples, data can also be pushed up, i.e., to a higher cache level. For example, data 254 from the level 3 cache 260 can be promoted to the level 2 cache 250. Similarly, data 244 from the level 2 cache 250 can be promoted to the level 1 cache 240. The cache manager 230 may promote the data based on an increased frequency of use, a recent occurrence of use, or for some other reason.

FIG. 3 shows additional example aspects of the cache manager 130. The cache manager 130 is seen to include the protocol selector 132, as well as a record 310 of data replacement protocols, a current protocol 330, a hit rate detector 340 and a protocol adjuster 350. The record 310 of data replacement protocols includes an entry for each of N data replacement protocols (P₁-P_(N)). The data replacement protocols P₁-P_(N) may include, for example, least recently used (LRU), first in first out (FIFO), random replacement, relative distance to logical block address (LBA), and/or other data replacement protocols. Each of the data replacement protocols P₁-P_(N) is associated with a weight. Protocols receiving more rewards than punishments tend to have larger weights, whereas protocols receiving fewer rewards than punishments tend to have smaller weights. Weights may be set with any suitable initial values. For instance, weights for all protocols may initially be set to be the same values or to random values.

In operation, the protocol selector 132 selects one of the data replacement protocols P₁-P_(N) for evicting data from each level of the multi-level cache 140. The selection process is random but has a biasing based on the weights associated with the different protocols. In an example, the probability of the protocol selector 132 selecting any given protocol is equal to the weight associated with that protocol divided by the sum of all the weights for all of the protocols.

The following example helps to illustrate the operation of the selection process employed by the protocol selector 132. In this particular example, it is assumed that there are four protocols and their weights are as follows:

Protocol Weight

P₁ 50

P₂ 2000

P₃ 300

P₄ 70

Here, the probability of the protocol selector 132 selecting protocol P₁ is 50 divided by 2420 (the sum of the weights), or 0.021, the probability of selecting P₂ is 2000/2420, or 0.83, and so forth.

The protocol selector 132 may operate to select a data replacement protocol in any suitable way. In one example, the protocols are represented as contiguous ranges of weights, which span from 1 to 2420 (the sum of the weights). For instance, a range for P₁ extends from 1 to 50, a range for P₂ extends from 50 to 2050, a range for P₃ extends from 2050 to 2350, and a range for P₄ extends from 2350 to 2420. The protocol selector 132 calculates a random number between 1 and 2420. The protocol selector 132 then identifies the selected protocol as the one that corresponds to the range into which the calculated random number falls. Thus, if the random number is calculated to be 2101.5234, the protocol selector 132 selects protocol P₃, because 2101.5234 falls in the range assigned to P₃ (from 2050 to 2350).

The current protocol 330 stores the protocol most recently selected by the protocol selector 132. The current protocol 330 is then put into effect for evicting data from each level of the multi-level cache 140. The hit rate detector 340 monitors cache hits and cache misses of the multi-level cache 140 with the selected protocol to compute a hit rate. In some examples, the hit rate detector 340 also monitors cache hits and cache misses for each of the cache levels 240, 250, and 260, individually, to compute a respective cache hit rate for each cache level. The protocol adjuster 350 adjusts the weights stored in the record 310 of data replacement protocols to dispense rewards and punishments based on whether the hit rate detector 340 observes an increase or decrease in the cache hit rate (or rates) once the selected protocol is put into place.

The protocol adjuster 350 can apply rewards and punishments with any suitable timing. In one example, the protocol adjuster 350 applies a reward or punishment each time the hit rate detector 340 detects a cache hit or a cache miss. Thus, each time the hit rate detector 340 detects a cache hit, the protocol adjuster 350 rewards the currently selected data replacement protocol. Similarly, each time the hit rate detector 340 detects a cache miss, the protocol adjuster 350 punishes the currently selected data replacement protocol. In this arrangement, individual cache hits indicate a cache hit rate of 100%, albeit over a short interval, whereas individual cache misses indicate a cache hit rate of 0%.

In another example, rewards and punishments are dispensed less frequently, such as after each occurrence of some predetermined number of read requests 218. For example, the protocol adjuster 350 can keep track of cache hits and cache misses that accumulate over some number of read requests 218. After the predetermined number of read requests 218 occur, the protocol adjuster 340 applies rewards and punishments for all cache hits and cache misses that have occurred during the interval all at once.

In yet another example, the protocol adjuster 350 dispenses rewards and punishments each time the protocol selector 132 makes a new selection of a data replacement protocol. For instance, just prior to each selection by the protocol selector 132, the protocol adjuster 350 applies rewards and punishments for all accumulated cache hits and cache misses that have occurred since the previous protocol selection.

The administration of rewards and punishments themselves can be effected in a number of ways. In one example, a reward is implemented simply by adding a number (e.g., 1) to the weight associated with the selected protocol. A punishment can be similarly effected by subtracting the number from the associated weight. Alternatively, rewards and punishments can be implemented by increasing and decreasing weights associated with selected protocols by a percentage. For instance, rewards can each operate by increasing the weight of a selected protocol by 1%, whereas punishments can each operate by decreasing the weight by 1%.

In some examples, the hit rate detector 340 identifies the particular cache level (240, 250, or 260) where the data requested in each read request 218 are found. The protocol adjuster 350 then applies rewards disproportionately based on the identified cache level. For example, a reward r may be applied for each cache hit when the requested data are found in the level 1 cache 240. However, the reward may be reduced to Ωr if the requested data are found in the level 2 cache 250, where Ω is a demotion factor taken to be a constant between zero and one (e.g., 0.7). Likewise, the reward may be reduced to Ω²r if the requested data are found in the level 3 cache 260.

Over time, for any given application and computing environment, it is expected that one of the data replacement protocols P₁-P_(N) will come to predominate over the others. Over multiple iterations, operation will thus tend to converge on a particular protocol.

Convergence maximizes use of the best data replacement protocol for the circumstances, but it can also prevent recovery and establishment of a new protocol if the circumstances change. For example, if the weight of one protocol is 1,000,000 and the weights of the others are all 0, the technique will not be able to recover and select a different protocol, even if new circumstances favoring the new protocol arise, as protocols with weights of 0 will never be selected.

In an example, the inability of the technique to adapt is avoided by limiting the minimum size of weights. For example, the protocol adjuster 350 may require no weight to fall below 5% of the sum of all the weights. Limiting the minimum weights in this way ensures that the technique can adapt as circumstances change. For example, a protocol that previously performed poorly can still be selected, at least some of the time, and can eventually come to predominate over the other protocols if it performs better than the other protocols.

In some implementations, it is desirable to prevent the protocol adjuster 350 from changing the weights of the data replacement protocols P₁-P_(N). For example, the computing circuitry 100 may be subject at certain times to maintenance or other operations, during which time processing will be different from that which is normal for the computing circuitry 100. During these kinds of circumstances, it may be undesirable for the protocol adjuster 350 to change the weights of the protocols, as doing so could impair efficiency of the cache 140 once normal processing is resumed. In an example, the protocol adjuster 350 includes an input 352 for receiving an enable signal. When the enable signal is true, the protocol adjuster 350 operates normally, dispensing rewards and punishments to the protocols P₁-P_(N) and thus allowing the weights of the protocols to change. But when the enable signal is false, the protocol adjuster 350 is disabled. No rewards or punishments are dispensed, and the weights of the protocols P₁-P_(N) remain constant at their previously established levels. Thus, it is possible to selectively enable the protocol adjuster 350 for normal operation and to disable the protocol adjuster 350 for abnormal operation. It should be understood that the protocol adjuster 350 can also be disabled for applications in which performance of the multi-level cache 140 is not critical. Thus, the protocol adjuster 350 can be selectively turned on or off to optimize the choice of data replacement protocols around particular applications or use cases.

In some implementations, the cache manager 130 selects and rewards data replacement protocols according to a formal reinforcement learning technique. Many such techniques are known; however, we have recognized that the SARSA λ technique is particularly well-suited for controlling the selection of data replacement protocols in a cache. SARSA is an acronym for State-Action-Reward-State-Action. A theoretical development of the SARSA λ technique can be found in “Reinforcement Learning: An Introduction,” by Richard S. Sutton and Andrew G. Barto, MIT Press, Cambridge, Mass., 1998.

According to an example SARSA λ implementation, we define a state variable “s” as the percentage of cache hits rounded to the nearest integer. This gives us a total of 101 possible values of the variable s (0 to 100, inclusive). In an example, the value of s is ascertained by computing an aggregate cache hit rate based on the hit rates of the individual cache levels 240, 250, and 260 of the multi-level cache 140, as follows:

$\begin{matrix} {s = {H_{Aggregate} = {{{ROUND}\left\lbrack \frac{100{\sum\limits_{L = 1}^{M}{H_{L}\Omega^{L - 1}}}}{\sum\limits_{L = 1}^{M}\Omega^{L - 1}} \right\rbrack}.}}} & (1) \end{matrix}$

Here, “L” is an index denoting the level of the cache 140, M denotes the total number of levels of the cache 140 (3 in this example), H_(L) denotes the hit rate of the L^(th) level of the cache 140 (as measured by the hit rate detector 340), and “Ω” denotes a demotion factor. In an example, Ω equals 0.7. Thus, a particular hit rate at the second level of the cache 140 contributes only 70% as much to the aggregate hit rate H_(Aggregate) as it would at the first level of the cache 140. Likewise, a particular hit rate at the third level of the cache 140 contributes only 49% as much to the aggregate hit rate as it would at the first level of the cache 140. Weighting hit rates in this manner ensures that cache hits at faster (lower numbered) levels of the cache 140 count more strongly in computing the aggregate hit rate than cache hits at slower (higher numbered) levels of the cache 140, and thus ensures that cache hits in the faster levels of the multi-level cache 140 are rewarded more strongly than cache hits at the slower levels.

We also define an action variable “a” as the selection of a data replacement protocol to be used in evicting data from each level of the multi-level cache 140. Thus, if the record 310 of protocols identifies a total of N different protocols, we have a total of N possible values for the action variable a, one for each protocol. We can refer to each selection of a data replacement protocol as a “play.”

Further, we define a state-action pair “(s, a)” as the concurrence of a particular aggregate cache hit rate (state) with a particular data replacement protocol selection (action). As there are 101 different states and N different actions, we have a total of 101*N unique state-action pairs. A policy “π” defines a mapping of each state-action pair (s, a) to the probability of taking an action while in the given state. Each state-action pair has a value, “Q^(π)(s, a),” which represents the average reward expected when taking action a in state s in accordance with the policy π.

A reward variable, “r,” is assigned a value based on the aggregate hit rate that results from selection of a particular state-action pair. For example, r may assume the following values:

r=3 if the aggregate hit rate is 96% or higher;

r=2 if the aggregate hit rate is 90% to 95%;

r=1 if the aggregate hit rate is 50% to 89%;

r=0 if the aggregate hit rate is less than 50%.

Here, higher rewards are associated with higher aggregate cache hit rates and rewards taper to zero for hit rates less than 50%. It is understood that these particular reward values are merely examples and that rewards may be tailored as desired to suit each particular situation. For example, a 50% aggregate hit rate could be a good number for certain caches (e.g., where the cache is very small in relation to the media it supports). For such caches, it might be appropriate to reward strongly a 50% aggregate hit rate.

Various parameters may be tuned to affect the performance of the learning process. A learning rate “α” is defined as a constant between zero and one that prescribes how much the value Q^(π)(s, a) of a state-action pair is biased from the results of a single action. Higher learning rates enable a system to respond more quickly to changes than lower learning rates. A discount rate “Y” is defined as a constant between zero and one that prescribes the present value of future expected rewards. A discount rate of one means no discounting, whereas a discount rate of zero means that immediate rewards are maximized. As the discount rate approaches one, the technique becomes more farsighted and takes future rewards into account more strongly. A trace-decay “λ” is also defined as a constant between zero and one. In an example, the learning rate α is set to 0.1, the discount rate Y is set to 0.7, and the trace-decay λ is set to 0.2. It is understood that these values are merely examples, and that different parameter values may be used to tune the learning process as desired.

A time displacement (TD) error δ drives all learning. For any given play, the TD error is updated by the following equation: δ_(t) =r _(t+1) +YQ(s _(t+1) ,a _(t+1))−Q(s _(t) ,a _(t))  (2) Thus, the TD error for time t is the reward for time t+1 plus the discounted value of the state-action pair at time t+1 minus the value of the state-action pair time t.

Further, an eligibility trace “e(s, a)” is associated with each state-action pair. For each play, if a state is visited and an action is taken, the value of the eligibility trace for that state-action pair is incremented by one. Eligibility traces essentially keep track of state-action pairs that are eligible for updating. The eligibility trace for state s and action a at time t is denoted e_(t)(s, a). All eligibility traces decay at a rate of Yλ. In mathematical terms, e _(t)(s,a)=Yλe _(t−1)(s,a) for s≠s _(t) , a≠a _(t), and e _(t)(s,a)=Yλe _(t−1)(s,a)+1, otherwise.  (3)

Using the definitions and parameters set forth above, a complete SARSA implementation for selecting and rewarding data replacement protocols in the multi-level cache 140 can be realized with the following pseudo-code. In an example, this pseudo-code is executed by the constructs shown in FIG. 3.

{01} Initialize Q(s, a) to small numbers on the interval [−1, 1] using a random number generator for all states

{02} Initialize e(s, a) to 0 for all states

{03} Initialize s, a

{04} Repeat for each play

-   -   {05} Take action a, observe resultant state s′ and reward r     -   {06} Choose a′ using policy derived from Q     -   {07} δ=r+YQ(s′, a′)−Q(s, a)     -   {08} e(s, a)=e(s, a)+1     -   {09} For all states s, actions a         -   {10} Q(s, a)=Q(s, a)+αδe(s, a)         -   {11} e(s, a)=Yλe(s, a)         -   {12} s=s′         -   {13} a=a′

At line 1 of the pseudo-code, each value of Q(s, a) is initialized to a random number between negative one and positive one. Assuming 101 possible states and N possible actions, line 1 involves initializing 101*N different values of Q(s, a). It should be noted that random initialization is merely an example. Alternatively, values of Q(s, a) can be initialized to predicted values, to values observed on earlier learning trials, or to other values.

At line 2 of the pseudo-code, all eligibility traces e(s, a) are initialized to zero. Using the numbers above, a total of 101*N values for eligibility traces are initialized.

At line 3, values of s and a are initialized. For example, a data replacement protocol (value of a) is chosen and the current aggregate cache hit rate (value of s) is computed using Equation (1).

Line 4 indicates a series of steps that are repeated for each play, i.e., for each selection of a data replacement protocol. At line 5, the action a (i.e., the data replacement protocol chosen at line 3) is selected and put into effect for evicting data from the multi-level cache 140. After a predetermined number of read requests 218 have occurred (or after some other defined interval), the hit rate detector 340 computes the aggregate hit rate (using Equation (1)) of the multi-level cache 140 observed since the selection, i.e., the aggregate hit rate that resulted from the action a. This hit rate is then taken as the resultant state, s′. It is noted that a particular reward r corresponds to the resultant state s′.

At line 6, a new action a′ is chosen. For example, the protocol selector 132 selects a protocol for evicting data from each level of the multi-level cache 140 using a random, biased selection process, similar to the one described above. As before, each protocol is assigned a weight. Here, the weight of each protocol “p” may be computed based on the sum of all Q(s, a_(p)) across all values of s, where a_(p) is the action of selecting the protocol p. The computed sums for each action are then used to weight the random, biased selection process as described in the previous example, such that protocols having higher weights will tend to be selected more often than protocols having lower weights. The probability of selecting any protocol p is thus proportional to the sum of all Q(s, a_(p)) divided by the sum of all values of Q(s, a).

According to one variant, the protocol having the highest weight is chosen for some fixed percentage of selections, while the random, biased selection process is used for the remainder of selections. In one example, the protocol having the highest weight is used for 70% of selections, with no variability, whereas random, biased selections are used for the remaining 30% of selections. Note that some of the random, biased selections will select the protocol having the highest weight, such that the total number of selections of the protocol with the highest weight is likely to be greater than 70%. The process of forcing the action with the highest weight to be selected for a high, fixed percentage of selections is known as “ε-greedy” selection.

According to a further variant, the random, biased selection process is used for all selections initially, but ε-greedy selection is introduced after some initial learning period. Alternatively, fixed selections can be introduced at a low rate (e.g., for 10% of selections) after an initial learning period, and the rate can be increased over time. It is noted, however, that, while an ε-greedy process may improve efficiency under any given set of circumstances, it also impairs the ability of the technique to recover quickly and to select a new protocol if circumstances favoring the new protocol should arise. Thus, it is not expected that optimal implementations will employ fixed selections at a rate above 90%.

The TD error is computed at line 7, and the eligibility trace for the current state-action pair is incremented at line 8.

Line 9 indicates a series of steps that are repeated for all states and actions. At lines 10 and 11, each value Q(s, a) and each value of e(s, a) for all s and all a is updated as indicated.

At steps 12 and 13, the current state s is assigned the value of s′ (the current aggregate hit rate), and the current action a is assigned the value of the most recent protocol selection, a′.

Control then returns to line 5, whereupon the action selected during the previous iteration of the loop is taken, i.e., the selected data replacement protocol is put into effect for evicting data from each level of the multi-level cache 140. After a predetermined number of read requests 218 or after some other defined interval, the hit rate detector 340 computes the aggregate hit rate of the multi-level cache 140 since the prior selection, i.e., that resulted from the action a. This aggregate hit rate is then taken as the resultant state, s′. A reward r, which corresponds to the state s′, is then applied. Operation continues in this matter indefinitely, with rewards steering future protocol selections toward more effective choices.

It is understood that SARSA λ approaches can be implemented in various ways. According to one alternative, the state variable s is allowed to take 101 values for each of the M levels of the multi-level cache 140, such that a total of 101^(M) states are possible (101 for the first cache level, times 101 for the second, and so forth), where each state represents a particular overall hit rate, i.e., a combination of hit rates across all M levels. Rewards can be applied disproportionately based on cache level. For example, a reward r_(L) for each level of the cache 140 is assigned substantially as above. Rewards for the individual levels are then combined to yield the total reward r as follows:

$\begin{matrix} {r = {\sum\limits_{L = 1}^{M}{\Omega^{L - 1}{r_{L}.}}}} & (4) \end{matrix}$

Here, “Ω” defines a demotion factor that applies progressively to lower levels of the cache 140. To illustrate, one can assume that Ω equals 0.7. Thus, using Equation (4), rewards at the second level of the cache 140 are worth only 70% as much as rewards at the first level, and rewards at the third level of the cache 140 are worth only 49% as much as rewards at the first level. This SARSA λ approach otherwise operates substantially as the one described above.

It is understood that the large number of states (101^(M)) used according to this alternative can be reduced to a more manageable number in various ways. For example, it may not be necessary to use 101 states to represent the hit rate at each cache level. Coarsely limiting the cache hit rate to fewer possible numbers can dramatically reduces the number of states. For example, reducing the cache hit rate at each level to a number between 1 and 10 reduces the number of states to 10^(M). Other techniques, such as function approximation, may also be used to reduce the size of the state space.

FIG. 4 shows an example process 400 for managing data replacement in a multi-level cache. The process 400 is typically carried out by the constructs described in connection with FIGS. 1-3, which reside in the memory 112 of the computing circuitry 100 and is run by the set of processors 110. The various acts of the process 400 may be ordered in any suitable way. Accordingly, embodiments may be constructed in which acts are performed in orders different from those illustrated, which may include performing some acts simultaneously, even though the acts are shown as sequential in the illustrated embodiments.

At step 410, one of multiple data replacement protocols is selected for evicting data from a multi-level cache. For example, the protocol selector 132 selects one of the protocols P₁-P_(N) for evicting data from each level of the multi-level cache 140. The selection is made in accordance with a selection process having a biasing that is adjustable to change the probability of selecting any of the data replacement protocols relative to the others. For example, the data replacement protocols P₁-P_(N) have weights that bias selection by the protocol selector 132 such that the protocol selector 132 is more likely to select protocols having higher weights than to select protocols having lower weights. In some examples, the protocol selector 132 selects the protocol having the highest weight a fixed percentage of the time (e.g., using an ε-greedy selection process), and uses the random, biased selection process the remainder of the time.

At step 412, data are evicted from each level of the multi-level cache 140 using the selected data replacement protocol. For example, once the protocol selector 132 selects a data replacement protocol, the cache manager 130 evicts data from each level 240, 250, and 260 of the multi-level cache 140 using the selected data replacement protocol. Thus, for instance, if the selected protocol is LRU, the cache manager 130 will evict data from each level of the multi-level cache 140 using the LRU protocol.

At step 414, a hit rate of the multi-level cache 140 is detected after selecting the selected data replacement protocol. For instance, the hit rate detector 340 detects whether a read request 218 results in a single cache hit or a single cache miss with the selected data replacement protocol. Alternatively (e.g., using the SARSA λ technique), the hit rate detector 340 measures the hit rate of the cache 140 since the last protocol selection. In some examples, hit rates of individual levels (e.g., 240, 250, and 260) of the multi-level cache 140 are detected. According to some variants, the hit rates of the individual levels are combined to produce an aggregate hit rate, which provides a weighted sum of the hit rates of the individual levels.

At step 416, the biasing of the selection process is adjusted, in response to the detected hit rate of the cache after selecting the selected data replacement protocol, to vary the probability that the selected data replacement protocol will later be selected according to the selection process when subsequently selecting one of the data replacement protocols for evicting data from the cache. In one example, the protocol adjuster 340 applies a reward to the selected protocol by increasing the weight associated with the selected protocol in the record 310 of data replacement protocols. As the weight of the selected protocol increases, the probability of the selected protocol being selected increases, so it is more likely to be selected going forward. In another example, values Q(s, a) of state-action pairs are updated in a SARSA λ reinforcement learning implementation.

An improved technique has been described for managing data replacement in a multi-level cache. The improved technique dynamically selects a data replacement protocol from among multiple candidates based on which data replacement protocol produces the greatest cache hit rate. One of multiple data replacement protocols is selected using a random selection process that can be biased to favor the selection of certain protocols over others. Data are evicted from the multi-level cache using the selected data replacement protocol, and the cache hit rate is monitored. The selected data replacement protocol is rewarded in response to the detected cache hit rate. The selection process is repeated, and a newly selected data replacement protocol is put into use. Each time a new selection is made, the cache hit rate is monitored and the selected protocol is rewarded based on the detected cache hit rate. In this fashion, operation tends to converge on an optimal data replacement protocol that best suits the application and current operating environment of the cache.

As used throughout this document, the words “comprising,” “including,” and “having” are intended to set forth certain items, steps, elements, or aspects of something in an open-ended fashion. Although certain embodiments are disclosed herein, it is understood that these are provided by way of example only and the invention is not limited to these particular embodiments.

Having described certain embodiments, numerous alternative embodiments or variations can be made. For example, the multi-level cache 140 has been shown and described as being realized in certain parts of the computing circuitry 100, for caching data stored on the disk 150. This is merely an example. Alternatively, the improved technique can be applied to caches in any part of a computing system.

The improved technique can also be applied to multi-level caches that locally store data, which is obtained from another computer or group of computers operated elsewhere. For example, the improvements can be applied to caches of files or software objects downloaded from other computers, such as Internet servers, to avoid the need to download the files or software objects each time they are needed. The technique can also be applied to host computers connected to a storage array, where the hosts each maintain a local cache of data stored on the array.

Further, although features are shown and described with reference to particular embodiments hereof, such features may be included in any of the disclosed embodiments and their variants. Thus, it is understood that features disclosed in connection with any embodiment hereof can be included as variants of any other embodiment hereof, whether such inclusion is made explicit herein or not.

Further still, the improvement or portions thereof may be embodied as a non-transient computer-readable storage medium, such as a magnetic disk, magnetic tape, compact disk, DVD, optical disk, flash memory, Application Specific Integrated Circuit (ASIC), Field Programmable Gate Array (FPGA), and the like (shown by way of example as medium 450 in FIG. 4). Multiple computer-readable media may be used. The medium (or media) may be encoded with instructions which, when executed on one or more computers or other processors, perform methods that implement the various processes described herein. Such medium (or media) may be considered an article of manufacture or a machine, and may be transportable from one machine to another.

Those skilled in the art will therefore understand that various changes in form and detail may be made to the embodiments disclosed herein without departing from the scope of the invention. 

What is claimed is:
 1. A method of managing data replacement in a multi-level cache, comprising: selecting, in accordance with a selection process, one of multiple data replacement protocols for evicting data from the multi-level cache, wherein the selection process has a biasing that is adjustable to change the probability of selecting any of the data replacement protocols relative to the others; evicting data from each level of the multi-level cache using the selected data replacement protocol; detecting a hit rate of the multi-level cache in response to the selected data replacement protocol; and adjusting the biasing of the selection process, in response to the detected hit rate of the multi-level cache after selecting the selected data replacement protocol, to vary the probability that the selected data replacement protocol will later be selected according to the selection process when subsequently selecting one of the data replacement protocols for evicting data from the multi-level cache, wherein detecting a hit rate of the multi-level cache includes detecting the hit rate of each cache level of the multi-level cache individually, wherein adjusting the biasing of the selection process includes applying a reward to the selected data replacement protocol, and wherein the reward applied is greater when detecting that the hit rate of a higher level of the multi-level cache increases than when detecting that the hit rate of a lower level of the multi-level cache increases by the same amount.
 2. The method of claim 1, wherein the reward applied is greater when detecting a higher hit rate at a level of the multi-level cache than when detecting a lower hit rate at the same level of the multi-level cache.
 3. The method of claim 2, wherein detecting the hit rate of the multi-level cache after selecting the selected data replacement protocol includes detecting a single cache hit or a single cache miss.
 4. The method of claim 2, wherein detecting the hit rate of the multi-level cache after selecting the selected data replacement protocol includes accumulating numbers of cache hits and cache misses over a designated interval of time and computing the hit rate based on the accumulated numbers of cache hits and cache misses.
 5. The method of claim 2, wherein detecting the hit rate of the multi-level cache after selecting the selected data replacement protocol includes accumulating numbers of cache hits and cache misses over a designated number of read requests and computing the hit rate based on the accumulated numbers of cache hits and cache misses.
 6. The method of claim 2, wherein detecting the hit rate of the multi-level cache after selecting the selected data replacement protocol includes combining the hit rates of the individual cache levels to produce an aggregate hit rate, wherein adjusting the biasing of the selection process is conducted in response to the aggregate hit rate.
 7. The method of claim 6, wherein the acts of selecting and adjusting are conducted in accordance with a SARSA λ reinforcement learning technique.
 8. The method of claim 1, wherein the selection process operates in a random, biased manner wherein each of the data replacement protocols is associated with a weight, and wherein the probability of selecting any of the data replacement protocols when selecting a data replacement protocol is proportional to the weight of the respective data replacement protocol divided by the sum of the weights of all of the data replacement protocols.
 9. The method of claim 8, wherein adjusting the biasing of the selection process includes limiting changes to the weights of the data replacement protocols to ensure that the probability of selecting any of the data replacement protocols does not fall below a lower limit greater than zero.
 10. Computing circuitry for managing data replacement in a cache, comprising: a set of processors; and memory, coupled to the set of processors and arranged to store instructions executable by the set of processors, wherein the set of processors executing instructions from the memory forms a controller constructed and arranged to: select, in accordance with a selection process, one of multiple data replacement protocols for evicting data from the multi-level cache, wherein the selection process has a biasing that is adjustable to change the probability of selecting any of the data replacement protocols relative to the others; evict data from each level of the multi-level cache using the selected data replacement protocol; detect a hit rate of the multi-level cache in response to the selected data replacement protocol; and adjust the biasing of the selection process, in response to the detected hit rate of the multi-level cache after selecting the selected data replacement protocol, to vary the probability that the selected data replacement protocol will later be selected according to the selection process when subsequently selecting one of the data replacement protocols for evicting data from the multi-level cache, wherein, when the controller is constructed and arranged to detect a hit rate of the multi-level cache, the controller is further constructed and arranged to detect the hit rate of each cache level of the multi-level cache individually, wherein, when the controller is constructed and arranged to adjust the biasing of the selection process, the controller is further constructed and arranged to apply a reward to the selected data replacement protocol, and wherein the reward applied is greater when detecting that the hit rate of a higher level of the multi-level cache increases than when detecting that the hit rate of a lower level of the multi-level cache increases by the same amount.
 11. The computing circuitry of claim 10, wherein the controller is constructed and arranged to operate the selection process in a random, biased manner wherein each of the data replacement protocols is associated with a weight, and wherein the probability of selecting any of the data replacement protocols when selecting a data replacement protocol is proportional to the weight of the respective data replacement protocol divided by the sum of the weights of all of the data replacement protocols.
 12. The computing circuitry of claim 10, wherein the reward applied is greater when detecting a higher hit rate at a level of the multi-level cache than when detecting a lower hit rate at the same level of the multi-level cache.
 13. A non-transitory computer-readable medium including instructions which, when executed by a set of processors of computing circuitry, cause the set of processors to perform a method for managing data replacement in a cache, the method comprising: selecting, in accordance with a selection process, one of multiple data replacement protocols for evicting data from the multi-level cache, wherein the selection process has a biasing that is adjustable to change the probability of selecting any of the data replacement protocols relative to the others; evicting data from each level of the multi-level cache using the selected data replacement protocol; detecting a hit rate of the multi-level cache in response to the selected data replacement protocol; and adjusting the biasing of the selection process, in response to the detected hit rate of the multi-level cache after selecting the selected data replacement protocol, to vary the probability that the selected data replacement protocol will later be selected according to the selection process when subsequently selecting one of the data replacement protocols for evicting data from the multi-level cache, wherein detecting a hit rate of the multi-level cache includes detecting the hit rate of each cache level of the multi-level cache individually, wherein adjusting the biasing of the selection process includes applying a reward to the selected data replacement protocol, and wherein the reward applied is greater when detecting that the hit rate of a higher level of the multi-level cache increases than when detecting that the hit rate of a lower level of the multi-level cache increases by the same amount.
 14. The non-transitory computer readable medium of claim 13, wherein adjusting the biasing of the selection process includes ensuring that the probability of selecting any of the data replacement protocols does not fall below a lower limit greater than zero.
 15. The non-transitory computer readable medium of claim 13, wherein the reward applied is greater when detecting a higher hit rate at a level of the multi-level cache than when detecting a lower hit rate at the same level of the multi-level cache.
 16. The non-transitory computer readable medium of claim 13, wherein detecting the hit rate of the multi-level cache after selecting the selected data replacement protocol includes detecting a single cache hit or a single cache miss.
 17. The non-transitory computer readable medium of claim 13, wherein detecting the hit rate of the multi-level cache after selecting the selected data replacement protocol includes accumulating numbers of cache hits and cache misses over a designated interval of time and computing the hit rate based on the accumulated numbers of cache hits and cache misses.
 18. The non-transitory computer readable medium of claim 13, wherein detecting the hit rate of the multi-level cache after selecting the selected data replacement protocol includes accumulating numbers of cache hits and cache misses over a designated number of read requests and computing the hit rate based on the accumulated numbers of cache hits and cache misses.
 19. The non-transitory computer readable medium of claim 13, wherein detecting the hit rate of the multi-level cache after selecting the selected data replacement protocol includes combining the hit rates of the individual cache levels to produce an aggregate hit rate, wherein adjusting the biasing of the selection process is conducted in response to the aggregate hit rate.
 20. The non-transitory computer readable medium of claim 13, wherein the acts of selecting and adjusting are conducted in accordance with a SARSA λ reinforcement learning technique. 